﻿using System;
using System.Net;

namespace FluentWebRequest
{
    internal class GetRequestMethodBuilder : IRequestMethodBuilder
    {
        private readonly string _url;
        private readonly string _parametters;
        private HttpWebRequest _webRequest;

        public GetRequestMethodBuilder(HttpWebRequest webRequest, string url, string parametters)
        {
            _webRequest = webRequest;
            _url = url;
            _parametters = parametters;
        }

        public HttpWebRequest GetDataFromUri()
        {
            var uri = string.IsNullOrEmpty(_parametters) ? new Uri(_url) : new Uri(_url + "?" + _parametters);

            _webRequest = (HttpWebRequest)WebRequest.Create(uri);
            _webRequest.Method = "GET";

            return _webRequest;
        }
    }
}